<?php namespace Admin\Controller;
class TypeAttrController extends CommonController{
	private $model;
 	public function __auto(){
 		$this->model=new \Common\Model\TypeAttr;
 	}
	public function index(){
		$tid=Q('get.tid',0,'intval');
		$data=$this->model->where("type_tid={$tid}")->get();
		// p($data);
		View::with('data',$data);
		View::make();
	}
	public function add(){
		$type_tid=Q('get.type_tid',0,'intval');
		if(IS_POST){
			if($this->model->store()){
				View::success("添加成功",U("TypeAttr/index",array('tid'=>Q('get.type_tid',0,'intval'))));
			}
			View::error($this->model->getError());
		}

		View::make();
	} 
	public function edit(){
		$taid=Q('get.taid',0,'intval');
		$data=$this->model->where("taid={$taid}")->find();
		$type_tid=$data['type_tid'];
		// p($data);
		if(IS_POST){
			if($this->model->edit()){
				View::success("修改成功",U('TypeAttr/index',array('tid'=>$type_tid)));
			}
			View::error($this->model->getError());
		}
		$taid=Q('get.taid',0,'intval');
		$oldData=$this->model->where("taid={$taid}")->find();
		View::with('oldData',$oldData);
		p($oldData);
		View::make();
	}
	public function del(){
		$taid=Q('get.taid',0,'intval');
		$data=$this->model->where("taid={$taid}")->find();
		$type_tid=$data['type_tid'];
		$this->model->where("taid={$taid}")->delete();
		View::success('删除成功',U('TypeAttr/index',array('tid'=>$type_tid)));
	}
}